<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>BON CAKE官网-高颜值的甜</title>
    <link rel="shortcut icon" href="https://www.boncake.com.cn/public/app/site/statics/logol.ico">
    <style>
        #header{
            overflow: hidden;
            width: 100%;
            height: 120px;
        }
        #footer{
            /* overflow: hidden; */
            width: 100%;
            height: 250px;
            margin-top: 20px;
        }
        .page-header{
            margin: 0 !important;
        }
    </style>

    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/gx-list.css">
    <link rel="stylesheet" href="../css/reset.css">

</head>

<body>
    <div id="header">
    </div>
    <!-- =============top================================== -->
    <div class="top">
        <div class="topcon">

            <div class="conhead">
                <span class="cars">全部商品</span>

                <p class="all">
                    <span class="turn">所有系列</span>
                    <img src="https://www.boncake.com.cn/themes/boncake/images/img/filter-icon.png" alt="">
                </p>
                <input type="text" placeholder="输入关键字">
                <img src="https://www.boncake.com.cn/themes/boncake/images/img/search-icon.png" alt="" class="search">
            </div>
        </div>
    </div>
    </div>
    <div class="hiden">
        <div class="kinds">
            <div class="kindscon">

                <section>
                    <div class="secleft">
                        <span>经典系列</span>
                        <p> CLASSIC SERIES</p>
                    </div>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/0b/29/c0/c48af4ca0bdfb4c304ec7834cf4897a565e3a327.jpg?1530243009#h"
                            alt=""></div>
                </section>

                <section>
                    <div class="secleft">
                        <span>星空系列</span>
                        <p>STARRY SKY</p>
                    </div>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/63/ab/6e/328e1fcc4b21cde6a86c7850d935795651edf7f2.jpg?1532067995#h"
                            alt=""></div>
                </section>
                <section>
                    <div class="secleft">
                        <span>生如夏花</span>
                        <p> SUMMER FLOWERS</p>
                    </div>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/94/72/de/5678569e95462e7c8924238dca74ad5f0dc5afd3.jpg?1562315162#h"
                            alt=""></div>
                </section>
                <section>
                    <div class="secleft">
                        <span>心花怒放 </span>
                        <p> WILD WITH JOY</p>
                    </div>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/f2/95/ab/83849e966936ba211a45c00c84037a2a7f3cf3c0.jpg?1555053733#h"
                            alt=""></div>
                </section>
                <section>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/f6/8c/92/b19ffefece6b34a086ab7e2b90df2f6ae1d20a2e.jpg?1529879806#h"
                            alt=""></div>
                    <div class="secleft">
                        <span>双层定制 </span>
                        <p> CUSTOMIZED PRO</p>
                    </div>
                </section>
                <section>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/67/86/d3/e9834fecef1662ee3a3e1706e4630b8fa784ede7.jpg?1529879465#h"
                            alt=""></div>
                    <div class="secleft">
                        <span> 甜蜜熊系列</span>
                        <p> HONEY BEAR</p>
                    </div>
                </section>
                <section>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/00/31/bc/d742701ff2ac7b40814365133cb89e401dd1b4ef.jpg?1535357111#h"
                            alt=""></div>
                    <div class="secleft">
                        <span>下午茶点 </span>
                        <p>TEA TIME</p>
                    </div>
                </section>
                <section>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/bf/1b/34/28fb6e48fa0f49fd90a64f57d0accb9c60eb9f78.jpg?1540456823#h"
                            alt=""></div>
                    <div class="secleft">
                        <span>炫酷星球 </span>
                        <p>BEAUTIFUL STAR</p>
                    </div>
                </section>
                <section>
                    <div class="secleft">
                        <span>梦幻乐园 </span>
                        <p> WILD WITH JOY</p>
                    </div>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/f4/15/e6/ed011f9c4983a4c481ab4e0241f2cb831628660e.jpg?1559209701#h"
                            alt=""></div>
                </section>
                <section>
                    <div class="secleft">
                        <span>莫兰迪花园 </span>
                        <p>MOLOANDI GARDEN</p>
                    </div>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/bd/62/4a/5325864126e089b8e31473f8b50259a4304a6b04.jpg?1568690355#h"
                            alt=""></div>
                </section>
                <section>
                    <div class="secleft">
                        <span>巴洛克系列</span>
                        <p>BAROCH LIST</p>
                    </div>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/cb/03/15/838f1864a3834f5e07f9f9963de10a748b3c59b3.jpg?1588052278#h"
                            alt=""></div>
                </section>
                <section>
                    <div class="secleft">
                        <span>小夏天 </span>
                        <p>SUMMER</p>
                    </div>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/fa/02/a8/7ee5eac8e4a5200ad73b3adc02a85e49ded0f887.jpg?1589452014#h"
                            alt=""></div>
                </section>
                <section>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/22/35/3c/e55a8e09f06de599de4dafb21acbea1ace14a0aa.jpg?1590476455#h"
                            alt=""></div>
                    <div class="secleft">
                        <span>小怪兽 </span>
                        <p>LITTLE MOSTER</p>
                    </div>
                </section>
                <section>
                    <div class="secright"><img
                            src="https://www.boncake.com.cn/public/images/67/08/bb/a2cdabbdd165ddc4eb4eb5ae6aaaad76cfd41941.jpg?1592380886#h"
                            alt=""></div>
                    <div class="secleft">
                        <span>中华小当家 </span>
                        <p>Small Home</p>
                    </div>
                </section>
            </div>
            <div class="kindsbot">
                <img src="https://www.boncake.com.cn/public/images/c2/95/dd/84d3646e4b8ec8d4767bd56f773e89307bd5b0d5.jpg?1582204398#w"
                    alt="">
                <img src="https://www.boncake.com.cn/public/images/04/78/79/38c11f2a794813b8771b31dcfc9fbe1d9ed2db5e.jpg?1582204459#w"
                    alt="">
                <img src="https://www.boncake.com.cn/public/images/e6/73/13/31204fb592b53754d2a1693700c371d9c16c2e37.jpg?1556273071#w"
                    alt="">
            </div>
        </div>
    </div>
    <!-- ====================list======================== -->
    <div class="row">
    </div>
    <!-- <div class="pageBox"></div> -->
    </div>
    <div id="footer">

    </div>
    <script src="../js/ajax.js"></script>
    <script src="../js/jquery-1.9.1.min.js"></script>

    <script>
        $('#header').load('header.html')
        $('#footer').load('footer.html')
        let oRow = document.querySelector('.row')
        // 存总条数
        // let total = 0
        // ajax是异步


        start()
        function start() {
            if (localStorage.getItem('pagenum') === null) {
                pageAjax(1)
            } else {
                // console.log(localStorage.getItem('pagenum'))
                pageAjax(localStorage.getItem('pagenum') - 0)
            }

            function pageAjax(n) {
                pAjax({
                    url: '../server/gx-list.php',
                    data: {
                        pagenum: n,
                        pagesize: 95
                    }
                }).then(function (res) {
                    // console.log(res);
                    // 解析数据
                    let json = JSON.parse(res)

                    // console.log(json)

                    // 存总条数，给分页使用
                    // total = json.total

                    // 先清空后渲染
                    oRow.innerHTML = ''

                    // 循环渲染页面
                    json.data.forEach(function (ele) {

                        let str = `<div class="col-sm-6 col-md-4">
                    <div class="thumbnail">

                        <img data-id="${ele.goods_id}" src="${ele.goods_introduce}" alt="...">
                      
                        <div class="caption">
                           
                            <h4>${ele.goods_name}</h4>
                            <p>￥${ele.goods_price}</p>

                            <span class="buy"><img src="https://www.boncake.com.cn/themes/boncake/images/img/btn-cart-icon.png" alt="">购买</span >
                        </div>
                    </div>
                </div>`

                        oRow.innerHTML += str
                    })
                })
            }
        }

       
        let arr = []
        // 事件委托

        oRow.addEventListener('click', function (ev) {
            // 查看详情
            if (ev.target.tagName === 'IMG' || ev.target.className === 'btn btn-primary') {
                let id = ev.target.getAttribute('data-id')
                window.location.href = 'hlxiangqing.html'
                localStorage.setItem('detailId', id)
                console.log(id)
            }

            // 加入购物车
            if (ev.target.className === 'buy') {
                let n = ev.target.parentNode.previousElementSibling.getAttribute('data-id')
                let iNow = 0
                // 去重
                function findArr(arr, n) {
                    for (let i = 0; i < arr.length; i++) {
                        // 有相同去++
                        if (arr[i].id === n) {
                            iNow = i
                            return true
                        }
                    }
                    return false
                }

                let flag = findArr(arr, n)
                if (flag) {
                    // count++
                    arr[iNow].count++
                } else {
                    // 没有值去填一个新对象
                    arr.push({
                        id: n,
                        img: ev.target.parentNode.previousElementSibling.src,
                        price: ev.target.previousElementSibling.innerHTML,
                        name: ev.target.previousElementSibling.previousElementSibling.innerHTML,
                        count: 1,
                        flag: false
                    })
                }

                console.log(arr)
                localStorage.setItem('zzh_shop', JSON.stringify(arr))
                // 存到本地
            }
        })
        // =====================================================
        // console.log($('.all'))
        setTimeout(function () {
            $('header .nav-menu .nav-a').removeClass('active')
            $('header .nav-menu .nav-a:nth-of-type(2)').addClass('active')
        }, 2000)
        $('.all').click(function () {
            $('.hiden').css({
                display: 'block',
                top: '92px',
                left: '0px'
            })
        })
        $('.hiden').click(function () {
            $('.hiden').css({
                display: 'none'
            })
        })
        $('.kinds').click(function (ev) {
            ev.cancelBubble = true
            return false
        })
        $('.cars').click(function () {
            $('.cars').css({
                background: '#000',
                color: '#fff'
            })
            start()

        })
        //  ===========================================================
        let asd = 0
        let turn = document.querySelector(".turn")
        let turnall = document.querySelectorAll(".secleft span")
        // console.log(turnall)

        $('.kindscon section').click(function () {
            let index = $(this).index()
            turn.innerHTML = turnall[index].innerHTML
            $('.hiden').css({
                display: 'none'
            })
            $('.cars').css({
                background: '#eee',
                color: 'black'
            })
            switch (index) {
                case 0:
                    asd = {
                        select: 'cat_two_id',
                        select1: 111
                    }
                    break;

                case 1:
                    asd = {
                        select: 'cat_two_id',
                        select1: 2222
                    }
                    break;

                case 2:
                    asd = {
                        select: 'cat_two_id',
                        select1: 333
                    }
                    break;

                case 3:
                    asd = {
                        select: 'cat_two_id',
                        select1: 444
                    }
                    break;

                case 4:
                    asd = {
                        select: 'cat_two_id',
                        select1: 555
                    }
                    break;

                case 5:
                    asd = {
                        select: 'cat_two_id',
                        select1: 666
                    }
                    break;

                case 6:
                    asd = {
                        select: 'cat_two_id',
                        select1: 777
                    }
                    break;

                case 7:
                    asd = {
                        select: 'cat_two_id',
                        select1: 222
                    }
                    break;

                case 8:
                    asd = {
                        select: 'cat_two_id',
                        select1: 999
                    }
                    break;

                case 9:
                    asd = {
                        select: 'cat_two_id',
                        select1: 1010
                    }
                    break;

                case 10:
                    asd = {
                        select: 'cat_two_id',
                        select1: 1111
                    }
                    break;

                case 11:
                    asd = {
                        select: 'cat_two_id',
                        select1: 1212
                    }
                    break;

                case 12:
                    asd = {
                        select: 'cat_two_id',
                        select1: 1313
                    }
                    break;

                case 13:
                    asd = {
                        select: 'cat_two_id',
                        select1: 1414
                    }
                    break;
            }

            pageAjax()
        })
        function pageAjax() {
            pAjax({
                url: '../server/list0.php',
                data: asd
            }).then(function (res) {

                let json = JSON.parse(res)

                console.log(json)

                oRow.innerHTML = ''

                json.data.forEach(function (ele) {

                    let str = `<div class="col-sm-6 col-md-4">
                    <div class="thumbnail">

                        <img data-id="${ele.goods_id}" src="${ele.goods_introduce}" alt="...">
                      
                        <div class="caption">
                           
                            <h4>${ele.goods_name}</h4>
                            <p>￥${ele.goods_price}</p>

                            <span class="buy"><img src="https://www.boncake.com.cn/themes/boncake/images/img/btn-cart-icon.png" alt="">购买</span >
                        </div>
                    </div>
                </div>`


                    oRow.innerHTML += str
                })

            })

        }



    </script>
</body>

</html>